package com.zhibang.config;

import com.zhibang.util.Result;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
public class GlobleException {
    // 认证异常处理
    @ExceptionHandler(UnauthenticatedException.class)
    public Result err1(UnauthenticatedException e){
        return Result.fail(1001,"请先登录");
    }
    // 授权异常处理
    @ExceptionHandler(UnauthorizedException.class)
    public Result err2(UnauthorizedException e){
        return Result.fail(1002,"您不具备访问权限");
    }

    @ExceptionHandler(Exception.class)
    public Result ex(Exception ex){
        ex.printStackTrace();
        return Result.fail(500,"服务器异常:"+ex.getMessage());
    }
}
